package gam.n1.areas.impl.a;

import gam.n1.achievement.iAchievement;
import gam.n1.achievement.iAchievementManager;
import gam.n1.areas.Area;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;

public class DefendVEvent implements Listener {
    private final Area a;
    public DefendVEvent(Area area){
        this.a = area;
    }
    @EventHandler(priority = EventPriority.HIGHEST)
    public void a(EntityDamageByEntityEvent e){
        Entity var1 = e.getDamager();
        if (var1 instanceof Player){
            Player var2 = (Player) var1;
            if (a.isRunning() && a.playerInGame(var2) && var2.isOnline()){
                iAchievementManager var3 = a.getAchievementManager();
                iAchievement<Double> var4 = var3.getAchievementByUUID(var1.getUniqueId().toString(), "Damage", Double.class);
                if (var4 != null){
                    var4.up(var5 -> var5 += e.getDamage());
                }
            }
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void k(EntityDeathEvent e){
        LivingEntity var1 = e.getEntity();
        EntityDamageEvent var2 = var1.getLastDamageCause();
        if (var2 != null){
            Entity var3 = var2.getEntity();
            if (var3 instanceof Player){
                Player var4 = (Player) var3;
                if (a.isRunning() && a.playerInGame(var4) && var4.isOnline()){
                    iAchievementManager var5 = a.getAchievementManager();
                    iAchievement<Integer> var6 = var5.getAchievementByUUID(var4.getUniqueId().toString(), "Kill", Integer.class);
                    if (var6 != null){
                        var6.up(var7 -> var7++);
                    }
                }
            }
        }
    }
}
